<?php
    require_once 'header.php';
   	require_once 'config.php';
	require_once 'Date.php';

	$exppass = $_REQUEST["expid"];
	$rs=getCategory();
	$rcredit = getCreditCards($_SESSION["userid"]);
	$expcont = getExpDetails($_REQUEST["expid"],$_SESSION["userid"]);

?>
	<script langugage="javascript" type="text/javascript">
	function saveExp() {
		if(document.addexp.expdesc.value == '') {
			alert("Please enter expense description.");
			document.addexp.expdesc.focus();
			return false;
		}
		else if(document.addexp.expamt.value == '') {
			alert("Please enter an amount.");
			document.addexp.expamt.focus();
			return false;
		}
		else if(document.addexp.expdate.value == '') {
			alert("Please enter a valid date.");
			document.addexp.expdate.focus();
			return false;
		}
		document.addexp.submit();
	}
	</script>
<h4>Edit Expense</h4>
<br/><br/>
<form name="addexp" action="index.php" method="post">
       <input type="hidden" id="idyear" name="year" value="<?=$_REQUEST["year"]?>" />
       <input type="hidden" id="idmonth" name="month" value="<?=$_REQUEST["month"]?>" />
       <input type="hidden" id="iddate" name="date" value="<?=$_REQUEST["date"]?>" />
       <input type="hidden" id="idaction" name="action" value="updateexp" />
       <input type="hidden" id="idexpid" name="expid" value="<?= $exppass ?>" />
<table cellspacing="0" cellpadding="0" style="width: 50%; border: 1px solid rgb(200,200,200);" align="center">
        <tr>
	    <th>Expense Category</th>
       <td>
            <select name="expcat" id="idselcategory" style="width: 250px;">
           <? foreach($rs as $row) { ?>
             <option value="<?=$row["category_id"]?>"><?=$row["category_name"]?></option>
            <? } ?>

            </select>
       </td>	
</tr>
<tr>
            <th>Expense Description</th>
       <td><input type="text" name="expdesc" id="idexpdesc" maxlength="100" style="width: 250px;" value="<?= $expcont["exp_desc"]?>" /></td>
</tr>
<tr>
            <th>Amount</th>
       <td>$ <input type="text" name="expamt" id="idexpamt" maxlength="10" style="width: 238px;" value="<?= $expcont["exp_amt"]?>"/></td>
</tr>
<tr>
            <th>Date</th>
       <td><input type="text" name="expdate" id="idexpdate" maxlength="10" style="width: 250px;" value="<?= $expcont["exp_date"]?>"/>
<span style="font-size: 8pt; font-style: italic;">(yyyy-mm-dd)</span>
</td>
</tr>
<tr>
            <th>Cash/Card?</th>
       <td>
   			<select name="trantype" id="idtrantype" style="width: 250px;">
<?php
	if(is_array($rcredit)) {
		foreach($rcredit as $row) { 
?>
            <option value="<?=$row["cc_id"]?>"><?=$row["cc_nickname"]?></option>
<?php
		}
	}
?>
            </select>

       </td>        </tr>
       <tr>


       </tr>
        <tr>
        <td align="center" colspan="4"><input type="button" name="expadd" id="idexpadd" value="Save" onclick="saveExp();" /></td>
        </tr>
        </table>
        </form>

       <br/>

</body>
</html>
